package protype;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Product implements Cloneable, Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 3180869993109215893L;

	private String infoStr;
	private int infoInt;

	public String getInfoStr() {
		return infoStr;
	}

	public void setInfoStr(String infoStr) {
		this.infoStr = infoStr;
	}

	public int getInfoInt() {
		return infoInt;
	}

	public void setInfoInt(int infoInt) {
		this.infoInt = infoInt;
	}

	@Override
	public String toString() {
		return "Product [infoStr=" + infoStr + ", infoInt=" + infoInt + "]";
	}

	@Override
	protected Object clone() throws CloneNotSupportedException {
		Product productClone = null;

		try {
			productClone = (Product) super.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}

		return productClone;
	}

	public Object deepClone() throws IOException, ClassNotFoundException {
		// 将对象写到流里
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(bos);
		oos.writeObject(this);
		// 从流里读回来
		ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
		ObjectInputStream ois = new ObjectInputStream(bis);
		return ois.readObject();
	}

}
